package com.me.batm.models;

import com.badlogic.gdx.math.Circle;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.me.batm.Utils;

public class InverseAura extends Aura {
	
	int [][]next = {
			{1, 0, 3, 2},
			{1, 2, 3, 0},
			{1, 3, 0, 2},
			{2, 0, 3, 1},
			{2, 3, 0, 1},
			{2, 3, 1, 0},
			{3, 0, 1, 2},
			{3, 2, 0, 1},
			{3, 2, 1, 0}
	};
	int cnt = 0;
	
	public InverseAura (int direction, float x, float y, float width, float height,
					Vector2 speed, float velocity, float radio) {
		super (direction, x, y , width, height, speed, velocity, radio);
	}
	

	@Override
	public void applyEffectOverPlayer(Player player) {
		player.reverseControl = true;
//		player.directionMultiplier[Player.LEFT] = 1;
//		player.directionMultiplier[Player.RIGHT] = -1;
//		player.directionMultiplier[Player.UP] = -1;
//		player.directionMultiplier[Player.DOWN] = 1;
		int rand = (int)(Math.random() * next.length);
//		Player.LEFT = 1; 
//		Player.RIGHT = 0;
//		Player.DOWN = 3;
//		Player.UP = 2;

		Player.LEFT = next[rand][0]; 
		Player.RIGHT = next[rand][1];
		Player.DOWN = next[rand][2];
		Player.UP = next[rand][3];

	}
	@Override
	public void removeEffectOverPlayer(Player player) {
//		System.out.println("removing effect");
		player.reverseControl = false;
		Player.LEFT = 0; 
		Player.RIGHT = 1;
		Player.DOWN = 2;
		Player.UP = 3;
	}
	
	@Override
	public boolean isColliding(GameObject object) {
		// TODO Auto-generated method stub
		//TODO Implement a more precise intersection method
		
		Rectangle rectangle = object.shape;
		if (new Circle(centerX, centerY, (int) (radio * 0.5)).contains(rectangle.x, rectangle.y)) {
			if (!this.collided) {
				this.collided = true;
				applyEffectOverPlayer((Player) object);
			}
			return true;
		} else if (!new Circle(centerX, centerY, radio).contains(rectangle.x, rectangle.y)){
			if (this.collided) {
				this.collided = false;
//				System.out.println(object.getClass());
				if (object instanceof Player) {
					removeEffectOverPlayer((Player) object);
				}
				
			}
			return false;
		}
		return false;
	}
}
